<?php include incTemplate('header');?>
<link rel="stylesheet" href="<?php echo HH;?>js/jquery.plugin/fancybox/jquery.fancybox-1.3.4.css">
<script type="text/javascript" src="<?php echo HH;?>js/jquery.plugin/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<script type="text/javascript" src="<?php echo HH;?>js/jquery.plugin/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript"
	src="<?php echo HH;?>js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="<?php echo HH;?>js/jquery.plugin/AjaxFileUploader/ajaxfileupload.js"></script>
<script type="text/javascript">
var editor;
var attachids = new Array();
$(function(){
	editor = fulleditor('content');

	$('#tabimglist').datagrid({
		title:'图片列表',
		nowrap: false,
		url:'/admin.php/product/pimglist',
		remoteSort: true,
		rownumbers:true,
		pageNumber:10000,
		singleSelect:true,
		queryParams:{uuid:"<?php echo $uuid;?>"},
		idField:'id',
	    columns:[[  
	              {field:'imgurl',title:'图片地址',width:450,formatter:function(value,rowdata,rowindex){
						return "<a  rel=\"pimg\" href=\'/"+value+"\'>"+value+"</a>";
		          }},  
	              {field:'isdef',title:'默认图片',align:'center',width:100,formatter:function(value,rowdata,rowindex){
		              if(value == 1){
		            	  return "<input type=\"radio\" name=\"isdef\" checked=\"checked\" value=\""+rowdata.id+"\"/>";
			          }else{
			        	  return "<input type=\"radio\" name=\"isdef\" value=\""+rowdata.id+"\"/>";
				      }
		          }},
	              {field:'createtime',title:'上传时间',width:180,align:'center'},
		          {field:'id',title:'操作',width:200,align:'center',formatter:function(value,rowdata,rowindex){
					  return "<input type=\"checkbox\" name=\"imgid[]\" style=\"display:none;\" checked=\"checked\" value=\""+value+"\"/><a href=\"javascript:insertImg('"+rowdata.imgurl+"')\">插入图片</a>&nbsp;|&nbsp;<a href=\"javascript:deleteimg('"+rowdata.id+"')\">删除图片</a>";
			      }}

	    ]],
	    onLoadSuccess:function(data){
			$("a[rel=pimg]").fancybox();
		}
	});


	$("#btn_upload").click(function(){
		var newsimg = $("#procimg").val();
		if(newsimg == ""){
			$.messager.alert('提示','上传图片不能为空！');
			return;
		}
		
		if(!isImg(newsimg)){
			$.messager.alert('提示','上传的图片类型不正确！');
			return;
		}
		
		$.ajaxFileUpload
		(
			{
				url:'/admin.php/product/addprocimg',
				secureuri:false,
				fileElementId:'procimg',
				dataType: 'json',
				data:{productid:'<?php echo $uuid;?>'},
				success: function (data, status)
				{
					if(data.success==true){
						$.messager.alert('提示','上传成功！');
						$('#tabimglist').datagrid("reload");
					}else{
						$.messager.alert('提示','上传时有误！');
					}
				},
				error: function (data, status, e)
				{
					$.messager.alert('异常信息',e); 
				}
			}
		)
		
	});
	
});
function newsadd(){
	var title = $("#title").val();
	if(title == "" && title == null){
		$.messager.alert('提示','标题不能为空！'); 
		return;
	}

	var content =tinyMCE.get('content').getContent();
	if(content.length<50){
		$.messager.alert('提示','内容不能少于50个字符！'); 
		return;
	}

	document.form1.submit();
	
}
</script>
</head>
<body class="body">
<form action="/admin.php/product/productadddo" id="form1" name="form1" method="post">
<input type="hidden" name="uuid" value="<?php echo $uuid;?>"/>
<table class="tab_form">
	<tr>
		<td>
			标题：<input type="text" name="title" id="title" class="w_250" />
		</td>
	</tr>
	<tr>
		<td>
		<textarea name="content" id="content" style="width:100%;height:450px; "></textarea>
		</td>
	</tr>
	<tr>
		<td  >
		<input type="file" name="procimg" id="procimg" size="35"/>&nbsp;&nbsp;<input type="button" id="btn_upload" value="上传"/></td>
	</tr>
	<tr id="tr_imglist">
		<td>
		<table id="tabimglist">
		</table>
		</td> 
	</tr>
	<tr>
		<td>
			<input type="button" onclick="newsadd()" value="添加"/>
		</td>
	</tr>
</table>
</form>
</body>
</html>
